<include file="common:header" />
<div id="header">
    <div class="header">
        <h1 class="tit">退款申请</h1>
    </div>
</div>

<input type="hidden" class="order_id" value="{$_GET['order_id']}"/>
<div class="good-ddxq-list">
    <div class="ddxq-div1">
        <img src="{$good.img}"/>
        <div class="ddxq-title">
            <p>{$good.name}</p>
            <p>{$good.spec_str}</p>
            <p class="ddqx-title-p">¥ {$good.price}</p>
            <!--<input class="number" type="text" value="{$good.num}"/>-->
            <div class="math-num">
                <span class="symbol reduce">-</span>
                <input class="tit-num number" type="text" value="{$good.num}"/>
                <input class="begin_num" type="hidden" value="{$good.num}"/>
                <span class="symbol plus">+</span>
            </div>
            <input class="price" type="hidden" value="{$good.price}"/>
            <input class="sum" type="hidden" value=""/>
            <input class="good_id" type="hidden" value="{$good.id}"/>
        </div>
    </div>
</div>

<div class="refund_reason">
    <p class="reason_show">退款原因
        <span class="quality" style="float: right;">请选择原因&nbsp;</span>
    </p>
    <p>退款金额：<span style=" color:#ec1e03;font-weight:bold;">￥<span class="refund_amt">{$good_sum}</span>元</span></p>
</div>

<p class="refund_tips">最多￥<span class="most">{$good_sum}</span></p>
<p class="refund_remark">
    退款说明：
    <input type="text" class="remark" placeholder="备注">
</p>
<form action="{:U('Order/img_deal')}" method="post" id="editself_form" enctype="multipart/form-data">
    <div class="enclosure">
        <p class="enclosure_tips">上传凭证
            <span style="float: right;" id="en_upload">点击上传凭证</span>
        </p>
    </div>
</form>
<p class="sava_btn" id="sava_btn">提交</p>
<p class="sava_btn" id="save_show" style="display: none">提交中...</p>


<div class="refund_reason_float">
    <div class="reason_top"></div>
    <div class="reason_div">
        <p class="reason_title">退款原因</p>
        <div class="reason_item">
            <ul>
                <li>质量问题<input type="radio" class="pull-right" name="reason"/></li>
                <li>做工瑕疵<input type="radio" class="pull-right" name="reason"/></li>
                <li>大小尺寸与描述不符<input type="radio" class="pull-right" name="reason"/></li>
                <li>颜色、款式、图案描述不符合<input type="radio" class="pull-right" name="reason"/></li>
                <li>尺寸拍错、不喜欢、效果不好<input type="radio" class="pull-right" name="reason"/></li>
                <li>七天无理由退换货<input type="radio" class="pull-right" name="reason"/></li>
                <li>其他<input type="radio" class="pull-right" name="reason"/></li>
            </ul>
        </div>
    </div>
</div>
<link rel="stylesheet" type="text/css" href="{:C('__STATIC__')}{:C('DEFAULT_THEME')}/Static/css/style.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/diyupload/css/webuploader.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/diyupload/css/diyUpload.css">
<script type="text/javascript" src="__PUBLIC__/js/op.js"></script>
<script type="text/javascript" src="__PUBLIC__/diyupload/js/webuploader.html5only.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/diyupload/js/diyUpload.js"></script>
<script type="text/javascript">
    $('#en_upload').diyUpload({
        url:"{:U('Upload/refund_upload')}",
        success:function( data ) {},
        error:function( err ) {}
    });

    function del_img(obj)
    {
        $file_name = $(obj).data("file");
        $.ajax({
            url: "{:U('Upload/img_del')}",
            type: 'post',
            data: {img_name: $file_name},
            success: function (data) {
                if (data.status == "success") {
                    $(obj).parent("li").remove();
                    layer.msg("删除成功", {time: 1000});
                } else {
                    layer.msg(data.msg, {time: 1500});
                }
            }
        });
    }

    $(function(){
        $(".reason_top").click(function () {
            $(".refund_reason_float").animate({left:"-100%"} ,300);
        });

        $(".reason_show").click(function(){
            $(".refund_reason_float").animate({left:"0"} ,300);
        });
        $(".reason_item input").click(function(){
            $(".refund_reason_float").animate({left:"-100%"} ,300);
        });


        $(".pull-right").click(function () {
            var reason = $(this).parent().text();
            $(".quality").text(reason);
            $(".quality").attr('chose','chose');
        })

        $('.plus').click(function() {
            var num = $(this).parent().find('.number').val();
            num++;
            if(num > $(this).siblings('.begin_num').val()){
                layer.msg("数量不能大于原订单商品数量");return false;
            }
            $(this).parent().find('.number').val(num);
            $sum = accMul($(this).parent().find('.number').val(),$(this).parents(".ddxq-title").find(".price").val());
            $(this).parents(".ddxq-title").find(".sum").val($sum);
            sum()
        });


        //商品数量的减少
        $('.reduce').click(function() {
            var num = $(this).parent().find('.number').val();
            if(num >1) num--;
            $(this).parent().find('.number').val(num);
            $sum = accMul($(this).parent().find('.number').val(),$(this).parents(".ddxq-title").find(".price").val());
            $(this).parents(".ddxq-title").find(".sum").val($sum);
            sum()
        });

        $(".number").change(function () {
            if($(this).val()>$(this).next().val()){
                layer.msg("数量不能大于原订单商品数量");
                $(this).val($(this).next().val());
                return false;
            }
            $num_len = $(".number").length;
            for ($k=0;$k<$num_len;$k++){
                $good_sum =accMul($(".number").eq($k).val(),$(".number").eq($k).parents('.ddxq-title').find('.price').val());
                $(".number").eq($k).parents(".ddxq-title").find(".sum").val($good_sum);
            }
            sum()
        });

        $("#sava_btn").click(function () {

            var order_id = $(".order_id").val();
            var reason = $(".quality").text();

            var chose = $(".quality").attr('chose');

            var back_sum = $(".refund_amt").text();
            var back_remark = $(".remark").val();
            var good_ida =$(".good_id").val();
            var num_a = $(".number").val();

            if(!order_id){
                layer.msg("订单id不可为空",{icon:2,time:1000});
                return false;
            }
            if(!chose){
                layer.msg("退款原因不可为空",{icon:2,time:1000});
                return false;
            }
            if(!good_ida){
                layer.msg("商品ID不可为空",{icon:2,time:1000});
                return false;
            }
            if(!num_a){
                layer.msg("商品数量不可为空",{icon:2,time:1000});
                return false;
            }

            $("#sava_btn").hide();
            $("#save_show").show();

            var img_arr = new Array();
            var length = $(".diyFile").length;
            for($i=0;$i<length;$i++){
                var msg = $(".diyFile").eq($i).val();
                img_arr.push(msg);
            }

            $.ajax({
                url: "{:U('Order/back_money')}",
                type: "POST",
                data: {
                    order_id:order_id,
                    reason:reason,
                    back_sum:back_sum,
                    good_ida:good_ida,
                    num_a:num_a,
                    back_remark:back_remark,
                    img_arr:img_arr
                },
                success: function (msg) {
                    if (msg == "-1") {
                        layer.msg("已存在此订单中此商品的退款申请", {icon:2,time: 1000});
                        setTimeout(function() {window.location.reload()},800);
                    }else if(msg == "-2"){
                        layer.msg("申请失败", {icon:2,time: 1000});
                        setTimeout(function() {window.location.reload()},800);
                    }else{
                        layer.msg("申请已成功提交", {time: 1000});
                        setTimeout(function() {
                            window.location.href = "{:U('Order/order_confirm')}&id="+ order_id
                        }, 800);
                    }
                }
            });
        });
    });

    function sum() {
        var summoney = 0;
        $sum_len = $(".sum").length;
        for($l=0;$l<$sum_len;$l++){
            summoney = accAdd(summoney,$(".sum").eq($l).val());
        }
        $(".most").text(summoney);
        $(".refund_amt").text(summoney);
    }
</script>
<include file="common:footer" />